import dayjs from 'dayjs'

export const dateformat = function (date: Date = new Date(), formatstr: string) {
  var result = ''

  if (!date) return
  var _year = date.getFullYear() + ''
  var _month = date.getMonth() + 1 + ''
  _month = (_month.length == 1 ? '0' : '') + _month
  var _date = date.getDate() + ''
  _date = (_date.length == 1 ? '0' : '') + _date
  var _hour = date.getHours() > 9 ? date.getHours().toString() : '0' + date.getHours()
  var _minute = date.getMinutes() > 9 ? date.getMinutes().toString() : '0' + date.getMinutes()
  var _second = date.getSeconds() > 9 ? date.getSeconds().toString() : '0' + date.getSeconds()
  var format = formatstr || 'yyyymmdd'
  format = format.toLowerCase()
  switch (format) {
    case 'yyyy-mm-dd':
      result = _year + '-' + _month + '-' + _date
      break
    case 'y-m-d':
      result = _year + '-' + _month + '-' + _date
      break
    case 'yyyy-mm':
      result = _year + '-' + _month
      break
    case 'dd/mm/yyyy':
      result = _date + '/' + _month + '/' + _year
      break
    case 'mm/dd/yyyy':
      result = _month + '/' + _date + '/' + _year
      break
    case 'mm/dd/yyyy hh:mm:ss':
      result = _month + '/' + _date + '/' + _year + ' ' + _hour + ':' + _minute + ':' + _second
      break
    case 'yyyy-mm-dd hh:mm:ss':
      result = _year + '-' + _month + '-' + _date + ' ' + _hour + ':' + _minute + ':' + _second
      break
    case 'hh:mm:ss':
      result = _hour + ':' + _minute + ':' + _second
      break
    case 'yyyymm':
      result = _year + _month
      break
    case 'yyyymmddhhmmss':
      result = _year + _month + _date + _hour + _minute + _second
      break
    case 'yymm':
      result = _year.substr(2, 2) + _month
      break
    case 'yyyy':
      result = _year
      break
    case 'yyyymmdd':
      result = _year + _month + _date
      break
    default:
      result = _year + _month + _date
  }
  return result
}

export const dayFormat = () => {}
